﻿using KPIS.GERP.SERVICE.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace KPIS.GERP.MVC.Controllers
{
    public class EmployeeController : Controller
    {
        GERPContext db = new GERPContext();

        //
        // GET: /Employee/        

        public ActionResult Index()
        {
            return View();
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult GetPosition(int id)
        {
            var item = (from p in db.hrm_ps_employees
                        where p.emp_seq == id
                        select p.hrm_mp_positions).FirstOrDefault();
            return Json(item, JsonRequestBehavior.AllowGet);
        }

        [AcceptVerbs(HttpVerbs.Get)]
        public JsonResult GetEmployeeForCommandDetail(int id)
        {
            var item = (from p in db.hrm_ps_employees
                        where p.emp_seq == id
                        select p).FirstOrDefault();
            return Json(new {
                class_seq = item.class_seq,
                class_name = item.hrm_mp_classes != null ? item.hrm_mp_classes.class_name : null,
                pos_seq = item.pos_seq,
                pos_ref = item.hrm_mp_positions != null ? item.hrm_mp_positions.pos_ref : null,
                pos_name = item.hrm_mp_positions != null ? item.hrm_mp_positions.pos_name : null,
                exec_pos_seq = item.exec_pos_seq,
                exec_pos_name = item.hrm_mp_exec_positions != null ? item.hrm_mp_exec_positions.exec_pos_name : null,
                job_site_seq = item.hrm_mp_positions != null ? item.hrm_mp_positions.job_site_seq : null,
                job_site_name = item.hrm_mp_positions.hrm_mp_job_sites != null ? item.hrm_mp_positions.hrm_mp_job_sites.job_site_name : null,
                working_job_site_seq = item.working_job_site_seq,
                working_job_site_name = item.hrm_mp_job_sites != null ? item.hrm_mp_job_sites.job_site_name : null,
                salary = item.salary
            }, JsonRequestBehavior.AllowGet);
        }
    }
}
